#include "head.h"

void tcp_init(int *socketFD, char *ip, char *port){
    
    //创建socket套接字
    *socketFD = socket(AF_INET, SOCK_STREAM, 0);
    ERROR_CHECK(*socketFD, -1, "socket_tcpListen.c");

    //端口复用操作
    int rest = 1;
    int ret = setsockopt(*socketFD, SOL_SOCKET, SO_REUSEADDR, &rest, sizeof(rest));
    ERROR_CHECK(ret, -1, "setsockopt_tcpListen.c");
    
    //绑定ip和端口
    struct sockaddr_in Addr;
    Addr.sin_family = AF_INET;
    Addr.sin_port = htons(atoi(port));
    Addr.sin_addr.s_addr = inet_addr(ip);

    ret = bind(*socketFD, (struct sockaddr *)&Addr, sizeof(Addr));
    ERROR_CHECK(ret, -1, "bind_tcpListen.c");

    ret = listen(*socketFD, 10);
    ERROR_CHECK(ret, -1, "listen_tcpListen.c");


}

